package com.ruoyi.StarStudio.Controller;

import com.ruoyi.StarStudio.Entity.*;
import com.ruoyi.StarStudio.Service.StatisticalDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;

@RestController
@RequestMapping("/statistical_data")
public class StatisticalDataController {

    @Autowired
    StatisticalDataService statisticalDataService;

    @GetMapping()
    public Result getBankStatisticalData(){
        if (getLoginUser().getUser().isAdmin()){
            BankStatisticalData bankStatisticalData;
            try {
                bankStatisticalData = statisticalDataService.getBankStatisticalData();
            } catch (Exception e) {
                e.printStackTrace();
                return new Result(HttpStatusCode.ERROR, MessageConstant.GET_BANK_STATISTICAL_DATA_FAIL);
            }
            return new Result(HttpStatusCode.SUCCESS,MessageConstant.GET_BANK_STATISTICAL_DATA_SUCCESS,bankStatisticalData);
        } else {
            StoreStatisticalData storeStatisticalData;
            try {
                storeStatisticalData = statisticalDataService.getStoreStatisticalData();
            } catch (Exception e) {
                e.printStackTrace();
                return new Result(HttpStatusCode.ERROR,MessageConstant.GET_STORE_STATISTICAL_DATA_FAIL);
            }
            return new Result(HttpStatusCode.SUCCESS,MessageConstant.GET_STORE_STATISTICAL_DATA_SUCCESS,storeStatisticalData);
        }
    }
}
